package com.oocl.im.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.oocl.im.pojo.MsgPackage;

public class JsonUtil {

	public static String objectToString(MsgPackage msg) {
		ObjectMapper mapper = new ObjectMapper();
		String s = null;
		try {
			s = mapper.writeValueAsString(msg);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return s;
	}

	public static MsgPackage stringToObject(String jso) {
		MsgPackage msg = null;
		ObjectMapper mapper = new ObjectMapper();
		try {
			msg = mapper.readValue(jso, MsgPackage.class);
		} catch (JsonParseException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return msg;
	}

}
